package com.chagee.store.operation.server.service;

import com.chagee.base.utils.PaginationData;
import com.chagee.base.utils.PaginationRequest;
import com.chagee.store.operation.server.facade.TaskExecutionFacade;
import com.chagee.store.operation.server.model.param.ApprovalAppealParam;
import com.chagee.store.operation.server.model.param.TaskExecutionAppealRequest;
import com.chagee.store.operation.api.request.TaskExecutionRequest;
import com.chagee.store.operation.server.model.param.ViewReasonsParam;
import com.chagee.store.operation.server.model.vo.ApprovalAppealReasonResponse;
import com.chagee.store.operation.server.model.vo.mapVO.DictVo;
import com.chagee.store.operation.server.model.vo.mapVO.TaskExecutionMapVo;
import com.chagee.store.operation.api.response.TaskExecutionResponse;
import com.chagee.storeManagement.api.event.enums.ClosingInspectionEnum;
import com.chagee.storeManagement.api.event.enums.StoreTaskEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName TaskExecutionService  //类名称
 * @Description: //类描述
 * @Author: Jacky-zhan	//作者
 * @CreateDate: 2024/7/2 17:53	//创建时间
 * @UpdateUser: Jacky-zhan  //变更者
 * @UpdateDate: 2024/7/2 17:53	//更新时间
 * @UpdateRemark: //更新的信息
 * @Version: 1.0    //版本号
 */
@Slf4j
@Service
public class TaskExecutionService {

	@Resource
	private TaskExecutionFacade taskExecutionFacade;

	/**
	 * 门店数据字典
	 *
	 * @return 数据字典
	 */
	public TaskExecutionMapVo dict() {
		TaskExecutionMapVo taskExecutionMapVo = new TaskExecutionMapVo();
		//打烊验收
		List<DictVo> closingCheck = Arrays.stream(ClosingInspectionEnum.values()).map(ClosingInspectionEnum -> {
			DictVo vo = new DictVo();
			vo.setValue(String.valueOf(ClosingInspectionEnum.getType()));
			vo.setLabel(ClosingInspectionEnum.getDesc());
			return vo;
		}).collect(Collectors.toList());
		//开早验收
		List<DictVo> openCheck = Arrays.stream(StoreTaskEnum.values()).map(StoreTaskEnum -> {
			DictVo vo = new DictVo();
			vo.setValue(StoreTaskEnum.getType());
			vo.setLabel(StoreTaskEnum.getDesc());
			return vo;
		}).collect(Collectors.toList());
		//打烊验收
		taskExecutionMapVo.setCloseCheckDict(closingCheck);
		//开早验收
		taskExecutionMapVo.setOpenCheckDict(openCheck);
		return taskExecutionMapVo;
	}

	//查看任务 分页
	public PaginationData<TaskExecutionResponse> query(PaginationRequest<TaskExecutionRequest> request) {
		return taskExecutionFacade.query(request);
	}

	/**
	 * 查询工单下的任务信息（任务的申诉状态不为空的）
	 *
	 * @param request 工单编号
	 * @return 任务信息（任务的申诉状态不为空的）
	 */
	public List<TaskExecutionResponse> queryTaskExecutionList(TaskExecutionAppealRequest request) {
		return taskExecutionFacade.queryTaskExecutionList(request);
	}

	/**
	 * PC端开早打样工单-申诉信息：审批申诉（通过/驳回）
	 *
	 * @param approvalAppealParam 审批入参
	 * @return true/false
	 */
	public Boolean approvalAppeals(ApprovalAppealParam approvalAppealParam) {
		return taskExecutionFacade.approvalAppeals(approvalAppealParam);
	}

	/**
	 * PC端开早打样工单-申诉信息：查看驳回的原因/申诉原因
	 *
	 * @param viewReasonsParam 审批入参
	 * @return 申诉（驳回）原因证明
	 */
	public ApprovalAppealReasonResponse viewReasons(ViewReasonsParam viewReasonsParam) {
		return taskExecutionFacade.viewReasons(viewReasonsParam);
	}
}
